package com.example.zzl.adapter.HomeFragment;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.ImageView;

import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.example.zzl.adapter.MyBaseAdapter;
import com.example.zzl.model.bean.Home;
import com.example.zzl.utils.DisplayUtils;
import com.example.zzl.utils.specification.VolleySingleton;
import com.example.zzl.viewmodel.HomeFragment.HotSpecialPresenter;

import java.util.List;

/**
 * Created by ligg on 2017/2/11.
 */

public class HotSpecialAdapter extends MyBaseAdapter<Home.Special.ResultBean, HotSpecialAdapter.ViewHolder> {

    private HotSpecialPresenter presenter;

    public HotSpecialAdapter(Context context, List<Home.Special.ResultBean> list, int resId, HotSpecialPresenter presenter) {
        super(context, list, resId);
        this.presenter = presenter;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView imageView = null;
        if (convertView == null) {
            imageView = new ImageView(context);
            AbsListView.LayoutParams params = new AbsListView.LayoutParams(RecyclerView.LayoutParams.MATCH_PARENT, DisplayUtils.dipTopx(140));
            imageView.setLayoutParams(params);
            imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        } else {
            imageView = (ImageView) convertView;
        }

        Home.Special.ResultBean resultBean = list.get(position);
        imageView.setTag(resultBean.strSpecialImage);
        ((ImageView) imageView).setImageBitmap(null);
        final ImageView finalImageView = imageView;
        VolleySingleton.volleySingleton.getImageLoader().get(resultBean.strSpecialImage, new ImageLoader.ImageListener() {
            @Override
            public void onResponse(ImageLoader.ImageContainer response, boolean isImmediate) {
                if (finalImageView.getTag().equals(response.getRequestUrl())) {
                     finalImageView.setImageBitmap(response.getBitmap());
                }
            }

            @Override
            public void onErrorResponse(VolleyError error) {

            }
        });
        return imageView;
    }

    @Override
    public ViewHolder bindView(View convertView, List<Home.Special.ResultBean> list, int position) {
        return null;
    }

    @Override
    public void bindData(ViewHolder holder, List<Home.Special.ResultBean> list, int position) {

    }

    class ViewHolder extends MyBaseAdapter.BaseHolder {

        private View view;

        public ViewHolder(View view) {
            this.view = view;
        }
    }
}
